using System;
using System.Collections.Generic;
using System.Linq;

namespace SubSystem.Models.ObjectStore
{
    public class ObjectManager<T> where T : IStoreable
    {
        public ObjectManager(IObjectStore<T> repository)
        {
            Repository = repository;
        }

        protected IObjectStore<T> Repository { get; set; }

        public IEnumerable<T> Fetch()  
        {
            return Repository.Fetch();
        }

        public T FetchById(Guid id)
        {
            return Repository.Fetch().Where(t =>t.Id == id).FirstOrDefault();
        }

        public bool Save(T item)
        {
            return Repository.Save(item);
        }
    }

    public interface IStoreable
    {
        Guid Id { get; set; }
    }
}